using UnityEngine;
using System.Collections;

public class Cut : MonoBehaviour {

	public Transform hortela;
	public GameObject[] cutObjects;
	public Texture[] hortelas;
	public GameObject destroy;
	public GameObject AguaFervendo;
	public GameObject Cortar;
	public GameObject saveEnabled;
	int count;
	bool isCut;
	
	
	void Update () 
	{
		if(Input.GetButtonDown("Fire1") && !isCut)
		{
			isCut = true;
			cutObjects[0].SetActive(true);
			Destroy(destroy);
		}
		
		Ray ray = Camera.mainCamera.ScreenPointToRay(Input.mousePosition);
		RaycastHit hit;
		if(Physics.Raycast(ray,out hit, 200) && isCut)
		{
			transform.position = new Vector3(hit.point.x,transform.position.y,transform.position.z);
			if(Input.GetButtonDown("Fire1"))
			{
				if(count == 0 && transform.position.x > 14.79805f && transform.position.x < 15)
				{
					Debug.Log("Cortou");
					cutObjects[0].SetActive(false);
					cutObjects[1].SetActive(true);
					count ++;
					hortela.renderer.material.mainTexture = hortelas[0];
				}
				
				if(count == 1 && transform.position.x > 16.3992f && transform.position.x < 16.57f)
				{
					Debug.Log("Cortou2");
					cutObjects[1].SetActive(false);
					cutObjects[2].SetActive(true);
					count ++;
					hortela.renderer.material.mainTexture = hortelas[1];
				}
				if(count == 2 && transform.position.x > 17.32009f && transform.position.x < 17.54009f)
				{
					cutObjects[2].SetActive(false);
					cutObjects[3].SetActive(true);
					count ++;
					hortela.renderer.material.mainTexture = hortelas[2];
				}
				if(count == 3 && transform.position.x > 15.48815f && transform.position.x < 15.79107f)
				{
					cutObjects[3].SetActive(false);
					count ++;
					hortela.renderer.material.mainTexture = hortelas[3];
					Cortar.SetActive(false);
					AguaFervendo.SetActive(true);
					saveEnabled.SetActive(false);
					this.enabled = false;
				}
			}
		}
	}
}
